<template>
  <view class="Supplication">
    <view class="searchbox">
      <view class="search">
        <image
          src="https://www.123qifu.com/onlineimages/static/Shopping/sous.png"
          class="searchImg"
          mode=""
        ></image>
        <input
          type="text"
          value=""
          placeholder="每天为生活拍张照"
          class="searchInp"
          @focus="searchClick()"
        />
      </view>
    </view>
    <view class="content">
      <view class="title">精选内容</view>
      <view class="lis" v-for="(gambit, index) in Topiclist" :key="index">
        <view class="top">
          <image class="avtar" :src="gambit.user_avatar" mode="aspectFit" />
          <view class="rig">
            <view class="name">{{ gambit.user_nickname }}</view>
            <view class="tiem">{{ gambit.createtime | formatDate }}</view>
          </view>
          <view
            class="guanzhu"
            v-if="gambit.is_show == 2 ? true : false"
            @click="follow(gambit.user_id)"
            >关注</view
          >
          <view class="yiguanzhu" v-if="gambit.is_show == 1 ? true : false"
            >已关注</view
          >
        </view>
        <view class="tetx">
          <view
            class="tag"
            @click="join(gambit, gambit.topic_id, gambit.topicTitle)"
          >
            <span>#</span>{{ gambit.topicTitle }}
          </view>
          {{ gambit.content }}
        </view>
        <view class="imglis">
          <image
            v-for="(item, indexs) in gambit.images"
            v-if="item.length !== 0"
            :key="indexs"
            class="imgls"
            :src="img + item"
            mode="aspectFill"
            @click="picClcik(gambit.images, indexs)"
          />
        </view>
      </view>
      <view class="friends" v-if="Topiclist.length == 0"
        >暂时还没有内容哦~</view
      >
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      topicId: "", //话题ID
      Topiclist: [],
      img:"https://www.123qifu.com/"
    };
  },
  onLoad(options) {
    this.title = options.title;
    wx.setNavigationBarTitle({
      title: this.title,
    });
    this.topicId = options.id;
  },
  onShow() {
    this.getArticleList();
  },
  methods: {
    searchClick() {
      uni.navigateTo({
        url: "../Search/Search",
      });
    },
    async getArticleList() {
      let that = this;
      const res = await that.$myRequest({
        url: "index/getArticle",
        method: "POST",
        data: {
          topicId: that.topicId,
        },
      });
      if (res.data.code == 1) {
        that.Topiclist = res.data.data.data;
      }
    },
    //图片预览
    picClcik(item, index) {
      let that = this;
      let imgsArray = [];
      for (let i = 0; i < item.length; i++) {
        imgsArray.push(that.$IMG_URL + item[i]);
      }

      uni.previewImage({
        urls: imgsArray,
        current: imgsArray[index],
      });
    },
    // 加入话题
    join(item, id, title) {
      uni.setStorage({
        key: "topicDetail",
        data: item,
      });
      uni.navigateTo({
        url: "../Supplication/Supplication?id=" + id + "&title=" + title,
      });
    },
    // 关注
    async follow(userid) {
      let that = this;
      const res = await that.$myRequest({
        url: "user/addCare",
        method: "POST",
        data: {
          uid: userid,
        },
      });
      if (res.data.code == 1) {
        uni.showToast({
          title: "关注成功",
          icon: "none",
        });
        that.getArticleList();
      } else {
        uni.showToast({
          title: res.data.msg,
          icon: "none",
        });
      }
    },
  },
};
</script>

<style lang="scss">
page {
  background: #fff;
  min-height: 100vh;
  overflow-y: auto;
  position: relative;
}
.Supplication {
  .searchbox {
    box-sizing: border-box;
    width: 714rpx;
    height: 64rpx;
    background: #f4f4f4;
    border-radius: 32rpx;
    margin: 0 auto;
    .search {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      box-sizing: border-box;
      padding: 0 30rpx;
      .searchImg {
        display: block;
        width: 32rpx;
        height: 32rpx;
      }
      .searchInp {
        flex: 1;
        margin-left: 22rpx;
        font-size: 28rpx;
        font-weight: 400;
        color: #333333;
      }
      .searchInp::-webkit-input-placeholder {
        color: #999999;
      }
    }
  }
  .content {
    width: 100%;
    height: auto;
    // border-top: 20rpx solid #eee;
    margin: 26rpx auto 0;
    .title {
      width: 100%;
      height: 86rpx;
      box-sizing: border-box;
      padding: 0 30rpx;
      font-size: 30rpx;
      font-weight: 400;
      color: #999999;
      display: flex;
      align-items: center;
      border-bottom: 1rpx solid #eee;
    }
    .lis {
      width: 690rpx;
      min-height: 200rpx;
      box-sizing: border-box;
      padding: 30rpx 0;
      border-bottom: 1rpx solid #eee;
      overflow: hidden;
      margin: 0 auto;
      .top {
        display: flex;
        align-items: center;
        .avtar {
          display: block;
          width: 90rpx;
          height: 90rpx;
          border-radius: 50%;
          margin-right: 25rpx;
        }
        .rig {
          display: flex;
          flex-wrap: wrap;
          flex-direction: column;
          justify-content: center;
          .name {
            font-size: 30rpx;
            font-weight: 550;
            color: #333333;
          }
          .tiem {
            font-size: 20rpx;
            font-weight: 400;
            color: #999999;
          }
        }
        .guanzhu {
          position: absolute;
          right: 30rpx;
          width: 94rpx;
          height: 42rpx;
          border: 1rpx solid #c52b2e;
          border-radius: 21rpx;
          text-align: center;
          line-height: 42rpx;
          font-size: 26rpx;
          font-weight: 400;
          color: #c52b2e;
        }
        .yiguanzhu {
          position: absolute;
          right: 30rpx;
          width: 120rpx;
          height: 42rpx;
          border: 1rpx solid #e8e8e8;
          border-radius: 21rpx;
          text-align: center;
          line-height: 42rpx;
          font-size: 26rpx;
          font-weight: 400;
          color: #999999;
        }
      }
      .tetx {
        display: inline-block;
        margin-top: 25rpx;
        font-size: 28rpx;
        font-weight: 500;
        color: #333;
        line-height: 45rpx;
        text-align: justify;
        .tag {
          color: #303faf;
          display: inline-block;
          margin-right: 10rpx;
          white-space: nowrap;
          span {
            display: inline-block;
            margin-right: 5 rpx;
          }
        }
      }
      .imglis {
        width: 105%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        margin-top: 25rpx;
        .imgls {
          display: block;
          width: 220rpx;
          height: 220rpx;
          margin-right: 15rpx;
          margin-bottom: 15rpx;
          border-radius: 8rpx;
        }
      }
    }
    .lis:last-child {
      border-bottom: none;
    }
    .friends {
      font-weight: 400;
      color: #999999;
      font-size: 30rpx;
      display: flex;
      justify-content: center;
      padding-top: 200rpx;
    }
  }
}
</style>
